package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TElectronicFenceObjectVo;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectQueryBo;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectAddBo;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectEditBo;
import com.ruoyi.system.basicInformation.service.ITElectronicFenceObjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 电子围栏关联对象Controller
 * 
 * @author ruoyi
 * @date 2021-05-20
 */
@Api(value = "电子围栏关联对象控制器", tags = {"电子围栏关联对象管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/fenceObject")
public class TElectronicFenceObjectController extends BaseController {

    private final ITElectronicFenceObjectService iTElectronicFenceObjectService;

    /**
     * 查询电子围栏关联对象列表
     */
    @ApiOperation("查询电子围栏关联对象列表")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:list')")
    @GetMapping("/list")
    public TableDataInfo<TElectronicFenceObjectVo> list(TElectronicFenceObjectQueryBo bo) {
        startPage();
        List<TElectronicFenceObjectVo> list = iTElectronicFenceObjectService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出电子围栏关联对象列表
     */
    @ApiOperation("导出电子围栏关联对象列表")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:export')")
    @Log(title = "电子围栏关联对象", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TElectronicFenceObjectVo> export(TElectronicFenceObjectQueryBo bo) {
        List<TElectronicFenceObjectVo> list = iTElectronicFenceObjectService.queryList(bo);
        ExcelUtil<TElectronicFenceObjectVo> util = new ExcelUtil<TElectronicFenceObjectVo>(TElectronicFenceObjectVo.class);
        return util.exportExcel(list, "电子围栏关联对象");
    }

    /**
     * 获取电子围栏关联对象详细信息
     */
    @ApiOperation("获取电子围栏关联对象详细信息")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:query')")
    @GetMapping("/{id}")
    public AjaxResult<TElectronicFenceObjectVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTElectronicFenceObjectService.queryById(id));
    }

    /**
     * 新增电子围栏关联对象
     */
    @ApiOperation("新增电子围栏关联对象")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:add')")
    @Log(title = "电子围栏关联对象", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TElectronicFenceObjectAddBo bo) {
        return toAjax(iTElectronicFenceObjectService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改电子围栏关联对象
     */
    @ApiOperation("修改电子围栏关联对象")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:edit')")
    @Log(title = "电子围栏关联对象", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TElectronicFenceObjectEditBo bo) {
        return toAjax(iTElectronicFenceObjectService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除电子围栏关联对象
     */
    @ApiOperation("删除电子围栏关联对象")
//    @PreAuthorize("@ss.hasPermi('basicInformation:fenceObject:remove')")
    @Log(title = "电子围栏关联对象" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTElectronicFenceObjectService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
